const { app, BrowserWindow } = require('electron')
const url = require('url')
const path = require('path')
const process = require('process')
const exec = require('child_process').exec
const env = process.env.BUILD_ENV
function createWindow () {
  const win = new BrowserWindow({
    width: 1200,
    height: 1000,
    webPreferences: {
      nodeIntegration: true,
      webSecurity: false
    }
  })

  if(env == 'development'){
    win.loadURL('http://localhost:8080')
  }else{
    win.loadURL(url.format({
      pathname: path.join(__dirname,'index.html'),
      protocol: 'file',
      slashes : true
    }))
  }
  win.webContents.openDevTools()
}

app.whenReady().then(createWindow)

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    exec('cmd /c taskkill /f /t /im  tail.exe',(a,b,c)=>{})
    app.quit()
  }
})

app.on('activate', () => {
  if (BrowserWindow.getAllWindows().length === 0) {
    createWindow()
  }
})